package com.mcc.app.finish.service.impl;

import java.util.Date;
import java.util.List;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mcc.common.utils.DateUtils;
import com.mcc.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.mcc.app.finish.mapper.FinishedQualityStandardsMapper;
import com.mcc.app.finish.domain.FinishedQualityStandards;
import com.mcc.app.finish.service.IFinishedQualityStandardsService;

/**
 * 成品质量标准Service业务层处理
 *
 * @author gxy
 * @date 2025-04-03
 */
@Service
public class FinishedQualityStandardsServiceImpl implements IFinishedQualityStandardsService {

    @Autowired
    private FinishedQualityStandardsMapper finishedQualityStandardsMapper;

    /**
     * 查询成品质量标准
     *
     * @param id 成品质量标准ID
     * @return 成品质量标准
     */
    @Override
    public FinishedQualityStandards selectFinishedQualityStandardsById(Integer id) {
        return finishedQualityStandardsMapper.selectById(id);
    }

    /**
     * 查询成品质量标准列表
     *
     * @param finishedQualityStandards 成品质量标准
     * @return 成品质量标准
     */
    @Override
    public List<FinishedQualityStandards> selectFinishedQualityStandardsList(FinishedQualityStandards finishedQualityStandards) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (ObjectUtil.isNotEmpty(finishedQualityStandards)) {
            queryWrapper.like(ObjectUtil.isNotEmpty(finishedQualityStandards.getIndicatorName()), "indicator_name", finishedQualityStandards.getIndicatorName());
            queryWrapper.eq(ObjectUtil.isNotEmpty(finishedQualityStandards.getIndicatorTop()), "indicator_top", finishedQualityStandards.getIndicatorTop());
            queryWrapper.eq(ObjectUtil.isNotEmpty(finishedQualityStandards.getIndicatorLower()), "indicator_lower", finishedQualityStandards.getIndicatorLower());
        }
        return finishedQualityStandardsMapper.selectList(queryWrapper);
    }

    /**
     * 新增成品质量标准
     *
     * @param finishedQualityStandards 成品质量标准
     * @return 结果
     */
    @Override
    public int insertFinishedQualityStandards(FinishedQualityStandards finishedQualityStandards) {
        finishedQualityStandards.setCreateBy(SecurityUtils.getUsername());
        finishedQualityStandards.setCreateTime(new Date());
        return finishedQualityStandardsMapper.insert(finishedQualityStandards);
    }

    /**
     * 修改成品质量标准
     *
     * @param finishedQualityStandards 成品质量标准
     * @return 结果
     */
    @Override
    public int updateFinishedQualityStandards(FinishedQualityStandards finishedQualityStandards) {
        finishedQualityStandards.setUpdateBy(SecurityUtils.getUsername());
        finishedQualityStandards.setUpdateTime(new Date());
        return finishedQualityStandardsMapper.updateById(finishedQualityStandards);
    }

    /**
     * 删除成品质量标准
     *
     * @param id 成品质量标准ID
     * @return 结果
     */
    @Override
    public int deleteFinishedQualityStandardsById(Integer id) {
        return finishedQualityStandardsMapper.deleteById(id);
    }

    /**
     * 批量删除成品质量标准
     *
     * @param ids 成品质量标准ID
     * @return 结果
     */
    @Override
    public int deleteFinishedQualityStandardsByIds(Integer[] ids) {
        if (ids.length == 0) return 0;
        return finishedQualityStandardsMapper.deleteBatchIds(ListUtil.toList(ids));
    }
}
